package com.yf.controller.admin.im;

import java.util.List;
import java.util.Map;

import com.yf.entity.MsgEntity;
import com.yf.service.im.MsgService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.response.R;
import com.yf.consts.DaoConst;


/**
 * 消息Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Aug 29 17:47:08 CST 2018
 */
@RestController
@RequestMapping("/msg")
public class MsgController {
    @Autowired
    private MsgService msgService;

    /**
     * 列表消息
     */
    @RequestMapping("/list")
    @RequiresPermissions("msg:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<MsgEntity> msgList = msgService.queryList(params);
        return R.ok(new PageInfo(msgList));
    }

    /**
     * 查看消息
     */
    @SysLog("查看消息")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("msg:info")
    public R info(@PathVariable("id") Long id) {
        MsgEntity msg = msgService.get(id);

        return R.ok(msg);
    }

    /**
     * 保存消息
     */
    @SysLog("保存消息")
    @RequestMapping("/save")
    @RequiresPermissions("msg:save")
    public R save(MsgEntity msg) {
        msgService.save(msg);

        return R.ok(msg);
    }

    /**
     * 修改消息
     */
    @SysLog("修改消息")
    @RequestMapping("/update")
    @RequiresPermissions("msg:update")
    public R update(MsgEntity msg) {
        msgService.update(msg);

        return R.ok(msg);
    }

    /**
     * 删除消息
     */
    @SysLog("删除消息")
    @RequestMapping("/delete")
    @RequiresPermissions("msg:delete")
    public R delete(@RequestBody Long[]ids) {
        msgService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有消息
     */
    @SysLog("所有消息")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<MsgEntity> msgList = msgService.queryList(params);

        return R.ok(msgList);
    }

    /***********自定义开始***********/
}
